home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-03 / ansiterm.zip / FILESPEC.BAS < prev   
BASIC Source File  |  1991-03-15  |  2KB  |  81 lines

  1. ' FILESPEC.BAS by Ronny Ong, April 5, 1988 - 100% Public Domain
  2. ' Modified for P.D.Q. by Dave Cleary
  3. ' From The QBNews Volume 1 No. 5
  4. ' Compile:  BC /O FileSpec;
  5. ' Link:     See AnsiTerm.Bas for linking instructions
  6.  
  7. '$INCLUDE: 'PDQDecl.Bas'
  8.  
  9. FUNCTION GetFileSpec$ STATIC
  10.  
  11. DIM Regs AS RegType
  12. DIM EnvBlkSeg AS INTEGER, EnvBlkPtr AS INTEGER, Char AS INTEGER
  13.  
  14. ' The Program Segment Prefix is a 256-byte block which DOS
  15. ' creates below all normal transient programs loaded.  The PSP
  16. ' contains many important pieces of information about the
  17. ' transient program, including the location of its "environment
  18. ' block" in memory.
  19.  
  20. Regs.AX = &H6200 ' Int 21H, Function 62H is Get PSP.
  21. CALL INTERRUPT(&H21, Regs)
  22. DEF SEG = Regs.BX ' Select the segment containing the PSP.
  23.  
  24. ' Get the segment of the environment block, stored at offset 2CH
  25. ' in the PSP.
  26.  
  27. EnvBlkSeg = PDQPeek2(&H2C)
  28.  
  29. ' Now select the segment of the environment block itself.
  30. ' Environment blocks are always paragraph-aligned.  That is, they
  31. ' begin only on even 16-byte address boundaries.  Offset 0,
  32. ' therefore, is always the start of the block as long as the
  33. ' segment is set properly.
  34.  
  35. DEF SEG = EnvBlkSeg
  36.  
  37. ' Initialize a pointer to search forward sequentially through
  38. ' memory, looking for the double zero bytes which mark the end of
  39. ' the environment strings.
  40.  
  41. EnvBlkPtr = 0
  42.  
  43. DO
  44.   IF PEEK(EnvBlkPtr) = 0 THEN
  45.      IF PEEK(EnvBlkPtr + 1) = 0 THEN
  46.         EXIT DO
  47.      END IF
  48.   END IF
  49.   IF EnvBlkPtr = &H7FFF THEN ' Environment blocks are max of 32K.
  50.      PRINT "End of environment block not found!"
  51.      STOP
  52.   ELSE
  53.      EnvBlkPtr = EnvBlkPtr + 1
  54.   END IF
  55. LOOP
  56.  
  57. ' Skip over the double zeroes and the 2-byte word count which
  58. ' precedes the filespec.
  59.  
  60. EnvBlkPtr = EnvBlkPtr + 4
  61.  
  62. Temp$ = "" ' Initialize filespec.
  63.  
  64. ' Assemble Filespec, ensuring that it does not get too long.
  65.  
  66. DO
  67.   Char = PEEK(EnvBlkPtr)
  68.   IF Char THEN
  69.      Temp$ = Temp$ + CHR$(Char)
  70.      EnvBlkPtr = EnvBlkPtr + 1
  71.   END IF
  72. LOOP WHILE Char > 0 AND LEN(Temp$) < 80
  73.  
  74. ' At this point, Filespec could be used in an OPEN statement to
  75. ' read/write the EXE file, but for this demonstration, it is
  76. ' simply displayed.
  77.  
  78. GetFileSpec$ = Temp$
  79.  
  80. END FUNCTION
  81.